package sg.edu.nus.iss.vmcs.customer;

import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionListener;

import sg.edu.nus.iss.vmcs.util.WarningDisplay;

/*
 * Copyright 2003 ISS.
 * The contents contained in this document may not be reproduced in any
 * form or by any means, without the written permission of ISS, other
 * than for the purpose for which it has been supplied.
 *
 */

/**
 * This boundary object enables a drink to be displayed and selected. It also 
 * displays the stock availability of the drink
 * 
 * @version 1.0 11 Oct 2008
 * @author Toh Kim Huat
 */

public class DrinkSelectionItem extends Panel {
	
	private static final String NOT_IN_STOCK = "Not in Stock";

	/**
	 * Generated serial version uid
	 */
	private static final long serialVersionUID = -4105611074113652426L;

	/**
	 * The drink button
	 */
	private Button drinkButton;
	
	/**
	 * The price
	 */
	private TextField price;
	
	/**
	 * The stick state
	 */
	private WarningDisplay stockState;
	
	/**
	 * This constructor creates an instance of the object
	 */
	public DrinkSelectionItem() {
		
		this.setLayout(new GridLayout(1, 3));
		this.drinkButton = new Button();
		this.price = new TextField();
		this.price.setEditable(false);
		this.stockState = new WarningDisplay(NOT_IN_STOCK);
		this.add(this.drinkButton);
		this.add(this.price);
		this.add(this.stockState);
		
	}
	
	/**
	 * This operation activates or deactivates the drink selection item button.
	 * This operation also displays OUT OF STOCK messages where appropriate
	 * 
	 * @param active
	 *            Boolean to indicate whether the drink selection item button is
	 *            active
	 */
	public void setItemState(boolean active) {
		this.drinkButton.setEnabled(active);
        this.stockState.setState(!active);
	}
	
	/**
	 * This operation sets the name on the Drink Selection Item
	 * 
	 * @param name
	 *            The name
	 */
	public void setName(String name) {
		this.drinkButton.setLabel(name);
	}
	
	/**
	 * This operation sets the price on the Drink Selection Item
	 * 
	 * @param price
	 *            The price
	 */
	public void setPrice(int price) {
		this.price.setText(price + " C");
	}

	public void addListener(ActionListener actionListener) {
		this.drinkButton.addActionListener(actionListener);
	}

	public Button getDrinkButton() {
		return drinkButton;
	}

	public TextField getPrice() {
		return price;
	}

	public WarningDisplay getStockState() {
		return stockState;
	}
	
	
}
